import java.io.StringReader;
import java.util.List;

import net.pimpas.logging.serviceprovider.LoggingServiceProvider;
import net.pimpas.logging.serviceprovider.LoggingServiceProviderFactoryImpl;
import net.pimpas.xml.dom4j.serviceprovider.Dom4jServiceProvider;
import net.pimpas.xml.exception.XmlAccessException;
import net.pimpas.xml.exception.XmlParseException;
import net.pimpas.xml.serviceprovider.XmlServiceProvider;
import net.pimpas.xml.serviceprovider.XmlServiceProviderFactoryImpl;

import org.dom4j.Node;

public class PimpasXMLServiceProviderTeste {
	private final static LoggingServiceProvider logger = LoggingServiceProviderFactoryImpl.getLoggingServiceProvider(PimpasXMLServiceProviderTeste.class);
	
	@SuppressWarnings("unchecked")
	public PimpasXMLServiceProviderTeste() {
		logger.debug("done!");
		
		XmlServiceProvider xmlService = XmlServiceProviderFactoryImpl.getXmlServiceProvider();
		if(xmlService instanceof Dom4jServiceProvider) {
			Dom4jServiceProvider dom4j = (Dom4jServiceProvider) xmlService;
			String xml = "<root><name>pc</name></root>";
			StringReader reader = new StringReader(xml);
			try {
				dom4j.parse(reader);
				List<Node> nodes = dom4j.selectNodes("//name");
				for(int i=0;i<nodes.size();i++)
					logger.debug(nodes.get(i).getText());
				xml = null;
			} catch (XmlParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (XmlAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public static void main(String[] args) {
		new PimpasXMLServiceProviderTeste();
	}
}